package com.spring.gop.proj.controller;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.spring.gop.proj.interfaces.MovieService;
import com.spring.gop.proj.interfaces.NoticeService;
import com.spring.gop.proj.model.MovieChart;

@Controller
@RequestMapping("/main")
@SessionAttributes("movie")
public class MainController {

	@Autowired private NoticeService noticeService;
	@Autowired private MovieService movieService;
	
	@RequestMapping()
	public void main(Model model) {
		model.addAttribute("pageIdx", 0);
		model.addAttribute("notice", noticeService.selectLastNotice());
		model.addAttribute("bannerList", movieService.selectMovieBanner());
		model.addAttribute("currentMonth", Calendar.getInstance().getTime().getMonth() + 1);
		
		List<String> chartMargin = new ArrayList<String>();
		chartMargin.add("5%");
		chartMargin.add("38%");
		chartMargin.add("71%");
		model.addAttribute("chartMargin", chartMargin);
		
		int currentYear = Calendar.getInstance().get(Calendar.getInstance().YEAR);
		List<List<MovieChart>> movieChartList = new ArrayList<List<MovieChart>>();
		for(int i=1; i<=Calendar.getInstance().getTime().getMonth() + 1; i++) {

			List<MovieChart> list = movieService.selectMovieChart(currentYear, i);
			movieChartList.add(list);
		}
		model.addAttribute("movieChartList", movieChartList);
	}
}
